package com.yeyks.app.function.statistical;

import com.yeyks.common.constants.activity.RedisKeyPreConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HyperLogLogOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class ManagementStatisticalService {

    @Autowired
    private RedisTemplate redisTemplate;

    private HyperLogLogOperations hyperLogLogOperations;
    private String hyperLogLogKeyPre = RedisKeyPreConstant.STATISTICAL_MANAGEMENT_UNIQUE_VISITOR_PRE + "userId";

    @PostConstruct
    public void init() {
        hyperLogLogOperations = redisTemplate.opsForHyperLogLog();
    }

    //UV（Unique Visitor）独立访客
    public void recordUniqueVisitor(Integer userId) {
        hyperLogLogOperations.add(hyperLogLogKeyPre, userId);
    }

}
